package com.bw.controller;

import com.bw.domain.User;
import com.bw.service.UserService;
import com.bw.utils.common.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("user")
public class ListController {

    @Autowired
    UserService userService;

    @RequestMapping("list")
    public Result list(@RequestParam(defaultValue = "1") Integer pageNum, @RequestBody User user){
        PageHelper.startPage(pageNum,10);
        List<User> list=userService.getList(user);
        return  Result.success(new PageInfo<>(list));
    }

    @RequestMapping("del")
    public Result del(Integer id){
        boolean b = userService.removeById(id);
        return  b?Result.success():Result.fail();
    }
}
